$(function(){
	getInfo.init();
});
var getInfo = {
	init:function(){
		getInfo.moviesFun();
		getInfo.CinemaFun();
	},
	moviesFun:function(){
		var url = window.location.search; //获取url中"?"符后的字串
		var theRequest = {};
		if (url.indexOf("?") !== -1) {
		  var str = url.substr(1),
		  	  strs = str.split("&");
		  for(var i = 0; i < strs.length; i ++) {
		     theRequest[strs[i].split("=")[0]] = unescape(strs[i].split("=")[1]);
		  }
		}
		getMoviesUrl = '/search';
		if (theRequest.text) {
			FilmNames = {
				FilmId: theRequest.text
			};
		}
		else {
			FilmNames = {
				FilmId: '1'
			};
		}
		publicDom.post(getMoviesUrl,FilmNames,function(responseData){
			if (responseData.Code === 0) {
				var data = responseData.Data;
				var StartDate = new Date(data.StartDate);
				var datetime = StartDate.getFullYear()+"年"+(StartDate.getMonth()+1)+"月"+StartDate.getDate()+"日";
				var movieInfoHtml = $("#movieInfo").html();
				movieInfoHtml = movieInfoHtml.replace("{{FilmName}}",data.FilmName);
				movieInfoHtml = movieInfoHtml.replace("{{Cast}}",data.Cast);
				movieInfoHtml = movieInfoHtml.replace("{{Director}}",data.Director);
				movieInfoHtml = movieInfoHtml.replace("{{FilmIntro}}",data.FilmIntro);
				movieInfoHtml = movieInfoHtml.replace("{{FilmStatus}}",data.FilmStatus);
				movieInfoHtml = movieInfoHtml.replace("{{SessionPrice}}",data.SessionPrice);
				movieInfoHtml = movieInfoHtml.replace("{{StartDate}}",datetime);
				movieInfoHtml = movieInfoHtml.replace("{{Duration}}",data.Duration);
				movieInfoHtml = movieInfoHtml.replace("{{Version}}",data.Version);
				movieInfoHtml = movieInfoHtml.replace("{{Style}}",data.Style);
				$("#movieInfo").html(movieInfoHtml);
			}
			else {
				layer.msg(error.Msg);
			}
		},function(error){
			layer.msg(error.Msg);
		});
	},
	CinemaFun:function(){
		CinemaUrl = '/search/cinemainfo';
		FilmIds = {
			FilmId: '1'
		};
		publicDom.post(CinemaUrl,FilmIds,function(responseData){
			if (responseData.Code === 0) {
				var data = responseData.Data;
				// for (var i = 0; i < data.length; i++) {
					$("#cinema").append('<tr class="odd">'
                                                +'<td class="  sorting_1">'+data.CinemaName+'</td>'
                                                +'<td class=" ">'+data.Site+'</td>'
                                                +'<td class=" ">'+data.SessionPrice+'</td>'
                                                +'<td class=" "><button class="btn btn-warning btn-sm go_buy">选座购票</button></td>'
                                            +'</tr>');
				// }
				getInfo.choseSeat(data);
			}
			else {
				layer.msg(error.Msg);
			}
		},function(error){
			layer.msg('服务器连接失败');
		});
	},
	choseSeat:function(data){
		var html = $(".buy_ticker_layer").html();
		var datetime = new Date();
		var tomorrowtime = new Date().getTime()+86400000;
		var thirdDaytime = new Date().getTime()+2*86400000;
		var tomorrowtime = new Date(tomorrowtime);
		var thirdDaytime = new Date(thirdDaytime);
		var today = '('+(datetime.getMonth()+1)+'月'+datetime.getDate()+'日'+')';
		var tomorrow = '('+(tomorrowtime.getMonth()+1)+'月'+tomorrowtime.getDate()+'日'+')';
		var thirdDay = '('+(thirdDaytime.getMonth()+1)+'月'+thirdDaytime.getDate()+'日'+')';
		var movieStartTime = new Date(data.StartTime);
		var StartTime = movieStartTime.getHours()+':'+movieStartTime.getMinutes();
		$(".go_buy").click(function(){
			layer.closeAll();
			html = html.replace("{{today}}",today);
			html = html.replace("{{tomorrow}}",tomorrow);
			html = html.replace("{{thirdDay}}",thirdDay);
			html = html.replace("{{StartTime}}",StartTime);
			html = html.replace("{{Languatge}}",data.Languatge);
			html = html.replace("{{ScreenType}}",data.ScreenType);
			html = html.replace("{{SessionPrice}}",data.SessionPrice);
			html = html.replace("{{orderData}}",'StartTime='+StartTime);
			localStorage.setItem('db_FileName',data.FilmName);
			$(".layui-layer-content #dateList").html(html);
			layer.open({
			  type: 1,
			  skin: 'layui-layer-rim', //加上边框
			  area: ['700px', '500px'], //宽高
			  title: data.CinemaName+'电影院',
			  content: html
			});
		});
	}
}